Home:ALL Converter>Can't connect Python program to remote MySQL database over the same network

Can't connect Python program to remote MySQL database over the same network

Ask Time:2022-07-27T17:56:18         Author:Jhet Marlo Dela Cruz

Json Formatter

Can someone please help me? I am trying to make a simple python - MySQL connection. the code is running on my Dell-Windows Laptop, while the server is running on my Acer-Linux Laptop, they are connected on the same network. But upon running the query it prompts me with this error : Firewall is disabled for both. I tried pinging both of them vise versa and is working. In fact, I have a program with LibreOffice Base and they are interacting properly. But when I try to translate just a simple query in PYTHON seems like it is not working, I just don't know what could be the error on my code. Thank you so much for you help.

    Traceback (most recent call last):
  File "C:\Users\JM Dela Cruz\Documents\pyproj\myproject\test1.py", line 3, in <module>
    mydb = mysql.connector.connect(
  File "C:\Users\JM Dela Cruz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\mysql\connector\pooling.py", line 287, in connect
    return MySQLConnection(*args, **kwargs)
  File "C:\Users\JM Dela Cruz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\mysql\connector\connection.py", line 137, in __init__
    self.connect(**kwargs)
  File "C:\Users\JM Dela Cruz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\mysql\connector\abstracts.py", line 1095, in connect
    self._open_connection()
  File "C:\Users\JM Dela Cruz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\mysql\connector\connection.py", line 533, in _open_connection
    self._socket.open_connection()
  File "C:\Users\JM Dela Cruz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\mysql\connector\network.py", line 569, in open_connection
    raise InterfaceError(
mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on '198.168.101.42:3306' (10060 A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond)

My Python Code :

import mysql.connector

mydb = mysql.connector.connect(
  host="198.168.101.42",
  user="vsearch",
  password="vsearchpasswd",
  database="classicmodels",
  port="3306"
)

mycursor = mydb.cursor()

_SQL="Select * From employees"

myresult = mycursor.execute(_SQL)

print(myresult.fetchall())

Author:Jhet Marlo Dela Cruz,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/73135844/cant-connect-python-program-to-remote-mysql-database-over-the-same-network
yy